package com.zdx.yswl.ui.tool;

import android.content.Context;
import android.net.wifi.ScanResult;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.zdx.yswl.R;

import java.util.ArrayList;

/**
 * Created by lpw on 15-7-23.
 */
public class LsitWifiAdapter extends BaseAdapter
{
    private LayoutInflater inflater;
    private ArrayList<ScanResult> wifiInfoList;

    public LsitWifiAdapter(Context context, ArrayList<ScanResult> wifiInfoList)
    {
        inflater = LayoutInflater.from(context);
        this.wifiInfoList = wifiInfoList;
    }

    static class ViewHolder
    {
        private TextView wifiNameText;
    }

    @Override
    public int getCount()
    {
        return wifiInfoList.size();
    }

    @Override
    public Object getItem(int position)
    {
        return null;
    }

    @Override
    public long getItemId(int position)
    {
        return 0;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent)
    {
        ViewHolder holder;
        if (convertView == null)
        {
            // Log.e("创建ViewHolder", "创建Holder");
            holder = new ViewHolder();
            convertView = inflater.inflate(R.layout.wifi_name_item, null);
            holder.wifiNameText = (TextView)convertView
                    .findViewById(R.id.wifi_name_text);
            convertView.setTag(holder);
        }
        else
        {
            // Log.e("创建ViewHolder", "获取Holder");
            holder = (ViewHolder)convertView.getTag();
        }

        holder.wifiNameText.setText(wifiInfoList.get(position).SSID);
        return convertView;
    }
}
